<%-- 
    Document   : book_list
    Created on : Oct 25, 2011, 6:42:46 AM
    Author     : pudy
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="/header.jsp"></jsp:include>
    <script type="text/javascript">
        $(document).ready(function() {
            $('a.delete').click(function(e) {
                e.preventDefault();
            
                var answer = confirm("Do you want to delete this booking?");
            
                if (answer){
                    var parent = $(this).parent().parent();
            
                    $.ajax({
                        type: 'get',
                        url: 'flights',
                        data: 'action=view_book&mode=delete_book&id=' + parent.attr('id').replace('record-', ''),
                        beforeSend: function() {
                            parent.fadeTo('slow', 0.25);
                        },
                        success: function() {
                            parent.find('td').wrapInner('<div style="display: block;" />').parent().find('td > div').slideUp(300, function() {
                                parent.remove();
                            });
                        },
                        error: function() {
                            parent.stop().fadeTo('slow', 1);
                        }
                    });
                }
            });
        });
    </script>
    <h1>Booking List</h1>
    <table>
        <tr>
            <th>No</th>
            <th>Customer</th>
            <th>Origin City</th>
            <th>Destination City</th>
            <th>Origin Pool</th>
            <th>Destination Pool</th>
            <th>Code</th>
            <th>Action</th>
        </tr>
    <c:set var="ordinal" value="${0}" />
    <c:forEach items="${flightBooks}" var="flightBook">
        <c:set var="ordinal" value="${ordinal + 1}" />
        <tr id="record-${flightBook.id}">
            <td>${ordinal}</td>
            <td>${flightBook.userName}</td>
            <td>${flightBook.originCity}</td>
            <td>${flightBook.destinationCity}</td>
            <td>${flightBook.originPool}</td>
            <td>${flightBook.destinationPool}</td>
            <td>${flightBook.code}</td>
            <td><a class="delete" href="./flights?mode=delete_book&id=${flightBook.id}">Delete</a></td>
        </tr>
    </c:forEach>
</table>
    <hr/>
<jsp:include page="/footer.jsp"></jsp:include>